import 'package:flutter/material.dart';
import 'package:common/global/style.dart';
import 'package:common/l10n/localizations.dart';
import 'package:common/common.dart';

class SimpleConfirmDialog extends StatefulWidget {
  final double width;
  final String title;
  final String content;
  final Function onOK;
  final String okButtonString;

  static show(
      {@required BuildContext context,
      @required double width,
      @required String title,
      @required String content,
      @required Function onOK,
      String okButtonString = ""}) {
    showDialog(
        context: context,
        child: Dialog(
          child: SimpleConfirmDialog(
            width: width,
            title: title,
            content: content,
            onOK: onOK,
            okButtonString: okButtonString,
          ),
        ));
  }

  SimpleConfirmDialog(
      {@required this.width, @required this.title, @required this.content, @required this.onOK, this.okButtonString});

  @override
  State<StatefulWidget> createState() => _SimpleConfirmState();
}

class _SimpleConfirmState extends State<SimpleConfirmDialog> {
  @override
  Widget build(BuildContext context) {
    return Container(
      width: 200,
      child: Column(
        mainAxisSize: MainAxisSize.min,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Container(
              padding: EdgeInsetsDirectional.only(top: 20, start: 20),
              child: Text(
                widget.title,
                textScaleFactor: 1,
                style: TextStyle(color: TColor.textBlack, fontSize: 16),
              )),
          Container(
            alignment: AlignmentDirectional.center,
            margin: EdgeInsetsDirectional.only(
              start: 20,
              end: 20,
              top: 20,
            ),
            child: Text(
              widget.content,
              textScaleFactor: 1,
              style: TextStyle(fontSize: 14, color: TColor.textBlack),
            ),
          ),
          SizedBox(
            height: 20,
          ),
          Divider(
            thickness: 1,
            height: 1,
            color: TColor.dividerGray,
          ),
          Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              Expanded(
                flex: 1,
                child: GestureDetector(
                  behavior: HitTestBehavior.opaque,
                  onTap: () => Navigator.maybePop(context),
                  child: Container(
                    alignment: Alignment.center,
                    height: 45,
                    width: double.infinity,
                    child: Text(
                      AppLocalizations.of(context).cancel(),
                      textScaleFactor: 1,
                      style: TextStyle(fontSize: 14, color: TColor.textHint),
                    ),
                  ),
                ),
              ),
              Container(
                height: 45,
                width: 1,
                color: TColor.dividerGray,
              ),
              Expanded(
                flex: 1,
                child: GestureDetector(
                  behavior: HitTestBehavior.opaque,
                  onTap: () {
                    widget.onOK.call();
                    Navigator.maybePop(context);
                  },
                  child: Container(
                    alignment: Alignment.center,
                    height: 45,
                    width: double.infinity,
                    child: Text(
                      TUtil.isNotEmptyString(widget.okButtonString)
                          ? widget.okButtonString
                          : AppLocalizations.of(context).OK(),
                      textScaleFactor: 1,
                      style: TextStyle(fontSize: 14, color: TColor.primeColor),
                    ),
                  ),
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }
}
